﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TrilhaImovel.Core.Entities;
using SharpArch.Data.NHibernate;
using TrilhaImovel.Core.Repositories;
using NHibernate;
using NHibernate.Criterion;

namespace TrilhaImovel.Data
{
    public class EstateRepository : Repository<Estate>, IEstateRepository
    {

        #region IEstateRepository Members

        public IList<Estate> GetEstates(decimal latLeft, decimal lngLeft, decimal latRight, decimal lngRight)
        {
            //ICriteria criteria = Session.CreateCriteria<Estate>()
            //    .CreateAlias("PointLocation", "p")
            //    .Add(Restrictions.Between("p.Latitude", latRight, latLeft))
            //    .Add(Restrictions.Between("p.Longitude", lngLeft, lngRight));

            //return Session.CreateCriteria<Estate>().List<Estate>();

            var estates = Session.CreateQuery("from Estate e " +
                                              "where e.PointLocation.Latitude between :latRight and :latLeft and " +
                                              "e.PointLocation.Longitude between :lngLeft and :lngRight")
                                             .SetParameter<decimal>("latRight", latRight)
                                             .SetParameter<decimal>("latLeft", latLeft)
                                             .SetParameter<decimal>("lngLeft", lngLeft)
                                             .SetParameter<decimal>("lngRight", lngRight)
                                             .List<Estate>();

            return estates;
        }

        #endregion
    }
}
